/**
 *  预警预报应用深化-污染源分析-污染源类型占比
 *  Created by lins on 2018/7/17.
 */
'use strict';
angular.module("MetronicApp").directive('typePie', function () {
    return {
        scope: {
            id: "@",
            data: "="
        },
        restrict: 'EA',
        template: '',
        replace: true,
        link: function ($scope, element, attrs, controller) {
            function getOption(data) {
               var option = {
                    title : {
                        text: '污染源类型占比',
                        x:'center',
                        textStyle:{  //标题文字设置
                            fontSize: '20',
                            fontWeight: 'bold',
                            color: '#5AB1EF'
                        }
                    },
                    series : [
                        {
                            name:'面积模式',
                            type:'pie',
                            itemStyle: {
                                normal: {

                                    label: {
                                        show: true,//是否展示
                                        position: 'insideLeft',
                                        //显示series中data的name值
                                        formatter: '{b} {d}%'

                                    },
                                }
                            },
                            radius : [0,110],
                            center : ['50%', '50%'],
                            roseType : 'area',
                            data:[
                                {value:35.11, name:'工业源:',itemStyle:{normal:{color:'#2EC7C9'}}},
                                {value:19.02, name:'生活源:',itemStyle:{normal:{color:'#B6A2DE'}}},
                                {value:27.55, name:'移动源:',itemStyle:{normal:{color:'#5AB1EF'}}},
                                {value:11.5, name:'农业源:',itemStyle:{normal:{color:'#FFB980'}}},
                                {value:6.82, name:'天然源:',itemStyle:{normal:{color:'#D8807A'}}},
                            ]
                        }
                    ]
                };
                return option;
            }

            var myChart = echarts.init(document.getElementById('first'), 'macarons');
            myChart.setOption(getOption($scope.data));

            $scope.$watch('data', function (newVal, oldVal) {
                myChart.setOption(getOption(newVal));
            });
        }
    };
});
